import jieba.analyse


class TFIDFUtils:
    @staticmethod
    def extract_keywords(text_content, keywords_num=10, stopwords_path=None, with_weight=False):
        # 设置停用词
        if stopwords_path:
            jieba.analyse.set_stop_words(stopwords_path)
        keywords = jieba.analyse.extract_tags(sentence=text_content, topK=keywords_num, withWeight=with_weight)
        return keywords


class TextRankUtils:
    @staticmethod
    def extract_keywords(text_content, keywords_num=10, stopwords_path=None, with_weight=False):
        # 设置停用词
        if stopwords_path:
            jieba.analyse.set_stop_words(stopwords_path)

        keywords = jieba.analyse.textrank(text_content, topK=keywords_num, withWeight=with_weight)
        return keywords
